/**
 * 获取某栏目中首个专辑资源
 */
import {getFirstResourceInTopic} from "../api/CommonApi";

export default {
    name:'LoadFirstResourceInTopicMixin',
    data(){
        return{
            resourceData:{},
            loadFirstResourceInTopicSetting: {
                code: null,
                loading:false,
                fail:false,
            }
        }
    },
    methods:{
        setFirstResourceCOde(code){
            this.loadFirstResourceInTopicSetting.code = code;
        },
        //加载栏目首个元素
        loadFirstResourceInTopic(){
            const setting = this.loadFirstResourceInTopicSetting
            if(!setting.code) return;
            // 省流
            if(setting.loading) return;
            this.loadFirstResourceInTopicSetting.loading = true
            this.resourceData = {}
            return getFirstResourceInTopic(setting.code).then(res => {
                this.resourceData = res.result
            }).catch(() => {
                this.loadFirstResourceInTopicSetting.fail = true
            }).finally(() => {
                this.loadFirstResourceInTopicSetting.loading = false
            })
        }
    }

}
